<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<script>
    /*选择价表自动补全*/
    autoCompleteDrug("drugNameId");
    function autoCompleteDrug(inputId){
        var parentId=$("#parentId").val();
        if(!parentId){parentId=''}
        var storageId = $("#applyTableId .table-selected").find("td").eq(0).find("input").val();
        var url=ctx+"/doctor/prescriptionItem/autoComplete?drugClass=A&storageId="+storageId+"&parentId="+parentId;
        autoComplete(inputId,url,
            function(data){
                var rows = [];
                for(var i=0; i<data.length; i++){
                    rows[rows.length] = {
                        data:data[i],
                        value:data[i].priceId,
                        result:data[i].drugName
                    };
                }
                return rows;
            },function(data, i, max){
                return data.inputCode+"|"+data.drugName+"|  "+data.packageSpec+"|  "+data.packageUnit+"|  "+data.price+"元 |  "+data.firmName+"|库存量："+data.quantity;
            },function(event,data,formatted){
                    $('#drugCode').attr('value',data.drugCode);
                    $('#drugNameId').attr('value',data.drugName);
                    $('#singleDosage').attr('value',data.dosePerUnit);
                    $('#singleUnit').attr('value',data.doseUnits);
                    $('#firmId').attr('value',data.firmid);
                    $('#firmName').attr('value',data.firmName);
                    $('#price').attr('value',data.price);
                    $('#packageSpec').attr('value',data.packageSpec);
                    $('#packUnit').attr('value',data.packageUnit);
                    $('#packageUnit').attr('value',data.packUnit);
                    $('#sumPrice').attr('value',data.price);
                    $('#unit').attr('value',data.minUnits);
                    $('#minUnitsTranslate').attr('value',data.doseUnits);
                    $('#spec').attr('value',data.minSpec);
                    $('#inputCode').attr('value',data.inputCode);
                    $('#priceId').attr('value',data.priceId);
            })
    }
    function itemformSaveLoad(divId,formId,saveUrl,loadUrl){
        if($('#'+formId).parsley().validate()){
            /*添加药品表单隐藏，药品明细列表展开并显示相应的列*/
            $("#prescWesternItemDiv").attr("class","panel col-lg-12");
            hideShowTableTd("itemListTable",'3,4,6,7,8,11','1');
            $("#prescWesternItemFormDiv").hide();
            formSaveMethod(divId,formId,saveUrl,loadUrl);
        }
        return false;
    }
    function closeDiv(){
        /*添加药品表单隐藏，药品明细列表展开并显示相应的列*/
        $("#prescWesternItemDiv").attr("class","panel col-lg-12");
        hideShowTableTd("itemListTable",'3,4,6,7,8,11','1');
        $("#prescWesternItemFormDiv").hide();
    }

    function onFrequency(){
        calculatedquantity();
        var frequency = $('#frequency option:selected').text();
        var tag='立即';
        var tag2= '必要时';
        $("#num").removeAttr("data-parsley-required", "true");
        $("#abidance").attr("data-parsley-required", "true");
        if(frequency.indexOf(tag)!=-1 || frequency.indexOf(tag2)!=-1){
            $("#num").attr("data-parsley-required", "true");
            $("#abidance").removeAttr("data-parsley-required", "true");
        }
    }

    function calculatedquantity(){
        var inputItemForm = $("#inputItemForm").serialize();
        $.get("${ctx}/doctor/prescriptionItem/calculatedquantity",inputItemForm ,function(result) {
            var num = result.dataMap.num;
            $("#num").val(num);
            var num = $.trim($("#num").val());
            var price = $.trim($("#price").val());
            var sum = Number(num) * Number(price);
            $("#sumPrice").val(sum.toFixed(4));
        });
    }

</script>
<div class="panel-body">
    <form:form id="inputItemForm" data-parsley-validate="" modelAttribute="prescriptionItem" onsubmit="return itemformSaveLoad('prescWesternItemDiv','inputItemForm','${ctx}/doctor/prescriptionItem/save','${ctx}/doctor/prescriptionItem/index?applyId=${prescriptionItem.applyId}&inoroutFlag=1');" method="post" class="form-horizontal">
        <form:hidden path="applyId" id="applyId"/>
        <form:hidden path="parent.id" id="parentId"/>
        <div class="form-group">
            <label class="col-sm-2 control-label">药品名称</label>
            <div class="col-sm-4">
                <form:hidden path="unit" id="unit"/>
                <form:hidden path="spec" id="spec"/>
                <form:hidden path="repetition" id="repetition" value="1"/>
                <form:hidden path="inputCode" id="inputCode"/>
                <form:hidden path="drugCode" id="drugCode"/>
                <form:hidden path="priceId" id="priceId"/>
                <form:input path="drugName" htmlEscape="false" class="form-control"  maxlength="40" data-parsley-required="true" id="drugNameId" />
            </div>
            <label class="col-sm-2 control-label">频次</label>
            <div class="col-sm-4">
                <form:select path="frequency" id="frequency" class="form-control" onchange="onFrequency()"  data-parsley-required="true">
                    <form:options items="${fns:findFreqList()}" itemLabel="freqDesc" itemValue="id" htmlEscape="false"/>
                </form:select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">用药天数</label>
            <div class="col-sm-4">
                <form:input path="abidance" id="abidance"  onchange="calculatedquantity()" htmlEscape="false" class="form-control"  maxlength="40"/>
            </div>
            <label class="col-sm-2 control-label">途径</label>
            <div class="col-sm-4">
                <form:select path="channel" id="channel" class="form-control" data-parsley-required="true" onchange="adminDictFun(this,'isSkin')">
                    <form:options items="${fns:getSysDictList('ADMINISTRATION_DICT')}" itemLabel="label" itemValue="id" htmlEscape="false"/>
                </form:select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">单次用量</label>
            <div class="col-sm-4">
                <form:input path="singleDosage" id="singleDosage" onchange="calculatedquantity()" htmlEscape="false" class="form-control" maxlength="40" data-parsley-required="true" data-parsley-type="number"/>
            </div>
            <label class="col-sm-2 control-label">用量单位</label>
            <div class="col-sm-4">
                <input path="minUnitsTranslate" id="minUnitsTranslate" htmlEscape="false" class="form-control" readonly="true" maxlength="40" data-parsley-required="true" />
                <input type="hidden" id="singleUnit" name="singleUnit" value="singleUnit">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">药品数量</label>
            <div class="col-sm-4">
                <form:input path="num" id="num" htmlEscape="false" min="0" class="form-control"  maxlength="40" data-parsley-required="true" data-parsley-type="number" value="1" onchange="changeSumPrice('num','price','sumPrice')"/>
            </div>
            <label class="col-sm-2 control-label">包装单位</label>
            <div class="col-sm-4">
                <input type="hidden" name="packageUnit" id="packageUnit">
                <input  id="packUnit" htmlEscape="false" class="form-control" readonly maxlength="40" data-parsley-required="true" />
            </div>


        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">单价</label>
            <div class="col-sm-4">
                <form:input path="price" id="price" htmlEscape="false" class="form-control"  maxlength="40" data-parsley-required="true" readonly="true"/>
            </div>
            <label class="col-sm-2 control-label">包装规格</label>
            <div class="col-sm-4">
                <form:input path="packageSpec" id="packageSpec" htmlEscape="false" class="form-control"  maxlength="40" data-parsley-required="true" readonly="true"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">是否皮试</label>
            <div class="col-sm-4">
                <form:select path="isSkin" id="isSkin" class="form-control" data-parsley-required="true">
                    <form:options items="${fns:getDictList('YES_NO')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                </form:select>
            </div>
            <label class="col-sm-2 control-label">皮试结果</label>
            <div class="col-sm-4">
                <form:input path="skinResult" id="skinResult" htmlEscape="false" class="form-control"  maxlength="40" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">药品厂商</label>
            <div class="col-sm-4">
                <form:hidden path="firmId" id="firmId"/>
                <form:input path="firmName" htmlEscape="false" class="form-control"  maxlength="40" data-parsley-required="true" id="firmName" readonly="true"/>
            </div>
            <label class="col-sm-2 control-label">总价</label>
            <div class="col-sm-4">
                <form:input path="sumPrice" id="sumPrice" htmlEscape="false" class="form-control"  maxlength="40" data-parsley-required="true" readonly="true"/>
            </div>
        </div>
        <button class="btn btn-primary btn-lg btn-parsley" type="submit" >插入</button>    <%-- <button class="btn btn-primary btn-lg btn-parsley" type="submit">保存并继续</button> --%>    <button class="btn btn-default  btn-lg btn-parsley" type="button" onclick="closeDiv()">取消</button>
    </form:form>

</div>



